package com.woniuxy.school.online.repair.controller;


import com.woniuxy.commons.core.model.Result;
import com.woniuxy.school.online.repair.entity.RepairInfo;
import com.woniuxy.school.online.repair.entity.UserProject;
import com.woniuxy.school.online.repair.from.AddRepairForm;
import com.woniuxy.school.online.repair.service.RepairInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 维修表 前端控制器
 * </p>
 *
 * @author 吴彦祖
 * @since 2025年05月13日
 */
@RestController
@RequestMapping("/repairInfo")
@Api(tags = "维修中心")
public class RepairInfoController {
    @Autowired
    private RepairInfoService repairInfoService;

    /**
     * 新增报修录入
     */
    //@PostMapping(value = "/addRepair",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @PostMapping(value = "/addRepair")
    @ApiOperation("申请报修录入")
    public Result addRepair(@RequestBody AddRepairForm addRepairForm, @RequestHeader String token) {
        return repairInfoService.addRepair(addRepairForm, token) ? Result.getResult(String.class).setData("申请保修成功") : Result.getResult(String.class).setData("申请保修失败");
    }

    /**
     * 查询所有报修记录
     */
    @GetMapping("/getRepairInfos")
    @ApiOperation("查询所有报修记录")
    public Result<List<RepairInfo>> getRepairInfos() {
        return Result.getListResult(RepairInfo.class).setData(repairInfoService.getBaseMapper().selectList(null));
    }

    /**
     * 管理员审核报修记录
     */
    @ApiOperation("管理员审核报修记录")
    @GetMapping("/checkRepair")
    public Result checkRepair(Long repairId, @RequestHeader String token) {
        repairInfoService.checkRepair(repairId, token);
        return Result.getResult().setMessage("提交成功");
    }


    /**
     * 驳回维修申请
     */
    @GetMapping("/RejectRepair")
    public Result RejectRepair(Long repairId) {
        return null;
    }

    /**
     * 通过维修项目查询可用的维修员
     */
    @ApiOperation("通过维修项目查询可用的维修员")
    @GetMapping("/getUsdRepairUser")
    public Result<List<UserProject>> getUsdRepairUser(Long repairId) {
        return Result.getListResult(UserProject.class).setData(repairInfoService.getUsdRepairUser(repairId));
    }


    /**
     * 审核人员给维修记录指定维修员
     */
    @ApiOperation("审核人员给维修记录指定维修员")
    @PostMapping("/addRepairUser2Repair")
    public Result addRepairUser2Repair(Long repairId,Long repairPerson) {
        repairInfoService.addRepairUser2Repair(repairId,repairPerson);
        return Result.getResult().setMessage("指派维修员成功");
    }
}

